package DMSXL._2023Before.Array;
/*
public class generateMatrix_ {
    public static void main(String[] args) {
        Solution solution = new Solution();
        int n = 5;
        int[][] matrix = solution.generateMatrix(n);
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                System.out.print(matrix[i][j] + "   ");
            }
            System.out.println();
        }

    }
}

class Solution {
    public int[][] generateMatrix(int n) {
        int[][] matrix = new int[n][n];
        int maxnum = n * n;
        int num = 1;
        int circle = 0;

        while (circle < n/2){

            for (int i = circle; i < n - circle; i++) {
                matrix[circle][i] = num;
                num++;
            }

            for (int i = circle; i < n - circle - 1; i++) {
                matrix[i + 1][n - circle - 1] = num;
                num++;
            }

            for (int i = n - circle - 1; i > circle ; i--) {
                matrix[n- circle - 1][i - 1] = num;
                num++;
            }
            for (int i = n - circle - 1; i > circle + 1; i--) {
                matrix[i - 1][circle] = num;
                num++;
            }
            circle++;
        }
        if(num == maxnum){
            matrix[(n-1)/2][(n-1)/2] = maxnum;
        }
        return matrix;
    }
}*/